﻿using MixingStation.LTWebService;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

//本地操作Access数据帮助
namespace MixingStation
{
    class LocalCommonHelper
    {
        public static bool SetUploadFlag(List<DataGridViewRow> selectedRowList)
        {
            string idStr = "";
            foreach (DataGridViewRow item in selectedRowList)
                idStr += item.Cells["IdColumn"].Value.ToString() + ",";
            try
            {
                string sql = "update WeightRecord set IsUpLoad = " + true + " where id in (" + idStr.TrimEnd(',') + ")";
                if (!CommonHelper.DoOpreation(sql))
                    return false;
            }
            catch (Exception ex)
            {
                LogHelper.error("设置上传标志错误：" + ex.Message);
                return false;
            }
            return true;
        }

        public static DataTable BuildDTByCarInfo(carWS[] carArr)
        {
            DataTable dt = CreateCarDT();
            foreach (carWS car in carArr)
            {
                long belongCorp = car.belongCorp == null ? 2 : car.belongCorp.id;
                dt.Rows.Add(car.id, belongCorp, car.code, car.isDefaultTare, car.isCompare, car.tare);
            }
            return dt;
        }

        private static DataTable CreateCarDT()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ID", typeof(long));
            dt.Columns.Add("BelongCorp", typeof(long));
            dt.Columns.Add("Code", typeof(string));
            dt.Columns.Add("IsDefaultTare", typeof(bool));
            dt.Columns.Add("IsCompare", typeof(bool));
            dt.Columns.Add("Tare", typeof(decimal));
            return dt;
        }
    }
}
